package cn.iocoder.yudao.module.member.api.student;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.api.stundent.AdminStudentApi;
import cn.iocoder.yudao.module.member.api.stundent.dto.StudentEducationalExperienceRespDTO;
import cn.iocoder.yudao.module.member.api.stundent.dto.StudentInfoRespDTO;
import cn.iocoder.yudao.module.member.api.stundent.dto.StudentPageReqDTO;
import cn.iocoder.yudao.module.member.api.stundent.dto.StudentRespDTO;
import cn.iocoder.yudao.module.member.controller.admin.student.vo.StudentInfoRespVO;
import cn.iocoder.yudao.module.member.controller.admin.student.vo.StudentPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.studentEducationalExperience.vo.StudentEducationalExperienceRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.student.StudentDO;
import cn.iocoder.yudao.module.member.service.student.StudentService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@Validated
public class AdminAdminStudentApiImpl implements AdminStudentApi {

    @Resource
    private StudentService studentService;

    @Override
    public StudentRespDTO getStudent(Long id) {
        StudentRespDTO studentRespDTO=new StudentRespDTO();
        StudentDO studentDO=studentService.getStudent(id);
        BeanUtils.copyProperties(studentDO,studentRespDTO);
        return studentRespDTO;
    }

    @Override
    public PageResult<StudentInfoRespDTO> getEnterpriseStudentPage(StudentPageReqDTO studentPage) {
        StudentPageReqVO pageReqVO=new StudentPageReqVO();
        BeanUtils.copyProperties(studentPage,pageReqVO);
        PageResult<StudentInfoRespVO> studentInfoPage = studentService.getStudentInfoPage(pageReqVO);
        PageResult<StudentInfoRespDTO> pageResult=new PageResult<>();
        if(null==studentInfoPage || CollectionUtils.isEmpty(studentInfoPage.getList())){
            return pageResult;
        }
        List<StudentInfoRespVO> list = studentInfoPage.getList();
        List<StudentInfoRespDTO> sList=new ArrayList<>();
        list.stream().forEach(m->{
            StudentInfoRespDTO s=new StudentInfoRespDTO();
            BeanUtils.copyProperties(m,s);
            List<StudentEducationalExperienceRespDTO> educationalExperience=new ArrayList<>();
            List<StudentEducationalExperienceRespVO> e = m.getEducationalExperience();
            if(CollectionUtils.isNotEmpty(e)){
                e.stream().forEach(d->{
                    StudentEducationalExperienceRespDTO t=new StudentEducationalExperienceRespDTO();
                    BeanUtils.copyProperties(d,t);
                    educationalExperience.add(t);
                });
            }
            s.setEducationalList(educationalExperience);
            sList.add(s);
        });
        pageResult.setList(sList);
        pageResult.setTotal(studentInfoPage.getTotal());
        return pageResult;
    }

    @Override
    public List<StudentEducationalExperienceRespDTO> getStudentEducationalExperienceByStudentId(Long studentId) {
        List<StudentEducationalExperienceRespVO> list = studentService.getStudentEducationalExperienceByStudentId(studentId);
        List<StudentEducationalExperienceRespDTO> educationalExperience=new ArrayList<>();
        if(CollectionUtils.isNotEmpty(list)){
            list.stream().forEach(d->{
                StudentEducationalExperienceRespDTO t=new StudentEducationalExperienceRespDTO();
                BeanUtils.copyProperties(d,t);
                educationalExperience.add(t);
            });
        }
        return educationalExperience;
    }
}
